package Easy只出现一次;

import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;

public class Solution {
    public int singleNumber(int[] nums) {
        if (nums.length == 1)
            return nums[0];
        int only = -1;
        Map<Integer,Integer> map = new HashMap<>();
        for (int i:
                nums) {
            if (!map.containsKey(i)) {
                map.put(i, 1);
            }
            else{
                map.remove(i);
            }
        }
        for (Integer i:
                map.keySet()) {
            if (map.get(i) == 1)
                only = i;
        }
        return only;
    }
    public int singleNumber1(int[] nums) {
        int single = 0;
        for (int num : nums) {
            single ^= num;
        }
        return single;
    }
    @Test
    public void test(){
        System.out.println((int)'c'^0^(int)'t');
    }
}
